import { Injectable } from '@angular/core';
import { LeanCloudService } from 'app/utils/lean-cloud.service'
import { Observable } from 'rxjs'
import { PageService } from 'app/utils/page.service'
@Injectable()
export class ProjectManageService {

  constructor(
    private leanCloudService: LeanCloudService
  ) { }

  /**
   * 获取项目列表
   * @param page
   */
  getProjects(page: PageService) {
    return this.leanCloudService.send(
      ({ leancloud }) => leancloud.Query('project', page)
        .find()
    )
  }

  /**
   * 保存/更新项目
   * @param param
   */
  saveProject({ name }, id?) {
    var project = this.leanCloudService.Object.createWithoutData('project',id);

    project.set('name', name)

    return project.save()
  }

  /**
   * 删除项目
   * @param id
   */
  deleteProject(id) {
    var project = this.leanCloudService.Object.createWithoutData('project', id);
    return project.destroy()
  }
}
